/**
 * @param {number[][]} costs
 * @return {number}
 */
 var minCost = function(costs) {
  const l = costs.length;
  const dp = new Array(l).fill(0).map( _ => new Array(3).fill(0));
  dp[0] = [...costs[0]];
  for(let i = 1; i < l; i++) {
      dp[i][0] = costs[i][0] + Math.min(dp[i - 1][1], dp[i - 1][2]);
      dp[i][1] = costs[i][1] + Math.min(dp[i - 1][0], dp[i - 1][2]);
      dp[i][2] = costs[i][2] + Math.min(dp[i - 1][0], dp[i - 1][1]);
  }
  return Math.min(...dp[l - 1]);
};